﻿#region using
using System;
using Linq2Crm.ObjectModel;
using Linq2Crm.ObjectModel.DomainObject;
using SilverCrmSoap.CrmSdk;

#endregion

namespace SLApp_Test.Model
{
   public class BaseEntity : IDomainObject
   {
      #region Implementation of IDomainObject
      public Guid Id { get; set; }
      public string Name { get; set; }
      public RecordStateCode StateCode { get; set; }
      public int StatusCode { get; set; }
      public int? OrigStatusCode { get; set; }

      public virtual void ConvertingFromEntity()
      {
      }

      public virtual void ConvertedFromEntity()
      {
      }

      public virtual void ConvertingToEntity()
      {
      }

      public virtual void ConvertedToEntity()
      {
      }

      public virtual void ObjectCreated()
      {
      }
      #endregion

      private string schemaName;

      public string SchemaName
      {
         get
         {
            if (string.IsNullOrEmpty(schemaName))
            {
               AttributeParser parser = new AttributeParser(GetType());
               schemaName = parser.AnalyzeType().EntityName;
            }
            return schemaName;
         }
      }

      public EntityReference ToReference()
      {
	      EntityReference enityReference = new EntityReference() {LogicalName = SchemaName, Id = Id, Name = Name};
           
         return enityReference;
      }		
	}
}